This document explores how R Markdown can be used to create presentations, notebooks, and interactive graphics, along with examples for each.
R Markdown supports creating various types of presentations:
remark.js..pptx files from R Markdown.Example YAML header for ioslides:
---
title: "Data Analytics Overview"
author: "John Andrew"
output: ioslides_presentation
---
This will create a basic HTML slide deck with ioslides.
Example YAML header for Beamer:
---
title: "Statistical Analysis"
author: "John Andrew"
output: beamer_presentation
---
This setup will generate a Beamer PDF presentation with numbered sections.
Example YAML header for PowerPoint:
---
title: "Business Intelligence"
author: "John Andrew"
output: powerpoint_presentation
---
This setup outputs directly to a .pptx file.
R Markdown can produce interactive graphics using: -
Shiny: R’s web framework for dynamic, reactive content.
- HTML Widgets: A collection of R packages for
embedding interactive JavaScript widgets like plotly and
leaflet.
To ensure compatibility with both HTML and PDF, the code is in HTML output.
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
plot_ly(data = mtcars, x = ~mpg, y = ~hp, type = 'scatter', mode = 'markers')
If i render as HTML, this chunk will display an interactive Plotly scatter plot.
library(leaflet)
leaflet() %>%
addTiles() %>%
addMarkers(lng = -122.4194, lat = 37.7749, popup = "San Francisco")
An R Notebook is an extension of R Markdown that supports inline execution and interactive analysis.
plot(mtcars$mpg, mtcars$hp,
main = "Miles per Gallon vs Horsepower",
xlab = "Miles per Gallon",
ylab = "Horsepower")
library(DT)
datatable(mtcars)
R Notebooks support caching, which saves results of computationally expensive code chunks.
Sys.sleep(5) # Simulate a long computation
sum(rnorm(1e6))
## [1] -923.619
Example YAML for parameterized reports:
---
title: "Parameterized Report"
output: html_notebook
params:
sample_size: 20
region: "West"
---
This feature allows flexible, dynamic reports based on parameter values.
R Markdown supports different programming languages.
# Python calculation example
x = 10
y = 5
result = x * y
result
-- SQL query example
SELECT * FROM mtcars WHERE mpg > 20
# Bash command example
ls -l